import request from '../utils/request';

// 合同管理相关API
export const contractApi = {
  // 获取合同列表
  getContractList: (params) => {
    return request.get('/api/project-contracts/page', { params });
  },

  // 获取合同详情
  getContractDetail: (id) => {
    return request.get(`/api/project-contracts/${id}`);
  },

  // 创建合同
  createContract: (data) => {
    return request.post('/api/project-contracts', data);
  },

  // 更新合同
  updateContract: (id, data) => {
    return request.put(`/api/project-contracts/${id}`, data);
  },

  // 删除合同
  deleteContract: (id) => {
    return request.delete(`/api/project-contracts/${id}`);
  },

  // 根据项目ID获取合同列表
  getContractsByProject: (projectId) => {
    return request.get(`/api/project-contracts/project/${projectId}`);
  },

  // 上传合同文件
  uploadContractFile: (contractId, file) => {
    const formData = new FormData();
    formData.append('file', file);
    return request.post(`/api/project-contracts/${contractId}/upload`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
  },

  // 下载合同文件
  downloadContractFile: (contractId, fileId) => {
    return request.get(`/api/project-contracts/${contractId}/files/${fileId}/download`, {
      responseType: 'blob'
    });
  }
};